package com.businessportal.web.dataaccess.services;

import com.businessportal.web.dataaccess.dao.EventDao;
import com.businessportal.web.dataaccess.dao.IEventDao;
import com.businessportal.web.dataaccess.entities.Event;
import com.businessportal.web.dataaccess.entities.Login;

import java.util.Date;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;

/**
 * Created by Vadim on 7/4/14.
 */
public enum EventService {
    INSTANCE;

    private IEventDao dao = new EventDao();

    private EventService(){

    }

    public Event getEventById(Long id){
        return dao.getById(id);
    }

    public void UpdateEvent(Long id, Login owner, String title, boolean isPublic, Date startDate, Date endDate, Date when_notify_me, boolean notify_me, String event_color, String description){
        Event event = dao.getById(id);

        event.setOwner_id(owner.getId());
        event.setTitle(title);
        event.setIs_public(isPublic);
        event.setEvent_start_date(startDate);
        event.setEvent_end_date(endDate);
        event.setColor(event_color);
        event.setDescription(description);
        event.setNotify_me(notify_me);
        event.setWhen_notify_me(when_notify_me);

        dao.update(event);
    }

    public void Update(Event event){
        dao.update(event);
    }

    public Event save(Login owner, String title, boolean isPublic, Date when_notify_me, boolean notify_me,  Date startDate, Date endDate, String event_color, String description){

        Event event = new Event(owner.getId(), startDate, endDate, when_notify_me, notify_me, title, isPublic, event_color, description);

        dao.save(event);

        return event;
    }

    public Set<Event> getEventsForUser(Login user){
        return dao.getEventsForUser(user);
    }

    public void deleteById(Long id){
        dao.deleteById(id);
    }

    public Set<Event> getAllPublicEvents(Login user){
        return dao.getPublicEventsForUser(user);
    }

    public Set<Event> getEventWithNotification(){
        return dao.getEventWithNotification();
    }
}
